﻿using QldtSdh.DAL.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace QldtSdh.BLL
{
    class HeThong
    {
        internal static DAL.Models.AppUser GetNguoiSuDung(string tenDangNhap, string matKhau)
        {
            if (tenDangNhap == null || matKhau == null)
                return null;
            tenDangNhap = tenDangNhap.ToLower();
            using (var context = CEMS4UG_DHKHContext.GetContext())
            {
                var au = context.AppUserDbSet.Where(e => e.UserName.ToLower() == tenDangNhap && e.Password == matKhau).FirstOrDefault();
                return au;
            }

        }

        public static List<AppUser> GetList(bool isOnlyActive = false)
        {
            using (var db = CEMS4UG_DHKHContext.GetContext())
            {
                if (isOnlyActive)
                    return db.AppUserDbSet.Where(e => e.IsActive == true).OrderBy(e => e.FullName).ToList();
                else
                    return db.AppUserDbSet.OrderBy(e => e.UserName).ToList();
            }
        }

        internal static DAL.Models.AppUser GetNguoiSuDung(string tenDangNhap)
        {
            if (tenDangNhap == null)
                return null;
            tenDangNhap = tenDangNhap.ToLower();
            using (var context = CEMS4UG_DHKHContext.GetContext())
            {
                var au = context.AppUserDbSet.Where(e => e.UserName.ToLower() == tenDangNhap).FirstOrDefault();
                return au;
            }
        }
    }
}
